package com.zzg.demo.springbatch.demo.customer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.util.Assert;
import java.util.function.Consumer;

@Slf4j
public class MyConsumerWriter<T> implements ItemWriter<T> {

    private final Consumer<T> consumer;

    public MyConsumerWriter(Consumer<T> consumer) {
        Assert.notNull(consumer, "A consumer is required");
        this.consumer = consumer;
    }


    @Override
    public void write(Chunk<? extends T> chunk) throws Exception {
        chunk.getItems().forEach(consumer);
    }

}
